package com.dingding.service.recruit.core.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.common.core.base.daox.ICriteriaBaseDao;
import com.dingding.common.core.base.daox.ISQLBaseDao;
import com.dingding.common.core.beans.RecruitUser;
import com.dingding.facde.recruit.dto.DriverRecruitCityDTO;
import com.dingding.facde.recruit.dto.ResGetDriverRecruitInfoDTO;
import com.dingding.facde.recruit.dto.ResValidateCode;
import com.dingding.service.recruit.core.dao.IDriverRecruitDao;
import com.dingding.service.recruit.core.sql.DriverRecruitSQL;

/**
 * 
 * @ClassName: DriverRecruitDaoImpl 
 * @Description: 司机招募数据操作DAO接口
 * @author YHQ
 * @date 2016年11月11日 下午3:17:47
 * @since V2.5.6
 * 
 */
@Component("driverRecruitDao")
public class DriverRecruitDaoImpl implements IDriverRecruitDao{

	@Resource(name = "SQLBaseDao")
	private ISQLBaseDao sqlBaseDao;
	
	@Resource(name="criteriaBaseDao")
	private ICriteriaBaseDao criteriaBaseDao;
	
	private Logger log = Logger.getLogger(this.getClass());
	
	/**
	 * 
	 * @Title: getDriverRecruitCity 
	 * @Description: 获取司机招募城市
	 * @author YHQ 
	 * @since V2.5.6
	 * @return List<DriverRecruitCityDTO>    返回类型
	 * 
	 */
	@Override
	@Transactional(readOnly = true)
	public List<DriverRecruitCityDTO> getDriverRecruitCity() {
		
		// 获取司机招募城市列表
		List<DriverRecruitCityDTO> driverRecruitCityDTOs = null;
		
		try {
			driverRecruitCityDTOs = sqlBaseDao.listSqlToCustomBean(DriverRecruitCityDTO.class, DriverRecruitSQL.DRIVER_RECRUIT_CITY);
		} catch (Exception e) {
			log.error("获取司机招募城市出现异常  类：" + this.getClass() + " getDriverRecruitCity()", e);
		}
		
		return driverRecruitCityDTOs;
	}

	/**
	 * 
	 * @Title: getDriverRecruitInfo 
	 * @Description: 获取司机招募报名信息
	 * @param recruitInfo 客户端请求Bean
	 * @author YHQ 
	 * @since V2.5.6
	 * @return ResGetDriverRecruitInfo    返回类型
	 * 
	 */
	@Override
	@Transactional(readOnly = true)
	public ResGetDriverRecruitInfoDTO getDriverRecruitInfo(String telPhone) {
		
		try {
			return sqlBaseDao.sqlToCustomBeanUnique(ResGetDriverRecruitInfoDTO.class, DriverRecruitSQL.GET_DRIVER_RECRUIT_INFO, telPhone);
		} catch (Exception e) {
			log.error("获取司机招募报名信息时出现异常   类：" + this.getClass() + " getDriverRecruitInfo()", e);
		}
		
		return null;
	}

	/**
	 * 
	 * @Title: driverSignUp 
	 * @Description: 招募司机报名
	 * @param @param reqSignUpDTO 客户端请求Bean
	 * @author YHQ 
	 * @since V2.5.6
	 * @return int    返回类型
	 * 
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public Boolean driverSignUp(RecruitUser recruitUser) {
		
		try {
			return criteriaBaseDao.saveOrUpdate(recruitUser);
		} catch (Exception e) {
			log.error("招募司机报名时出现异常   类：" + this.getClass() + " driverSignUp()", e);
		}
		
		return false;
	}

	/**
	 * 
	 * @Title: getRecruitUser 
	 * @Description: 获取招募司机报名信息
	 * @param telPhone 手机号
	 * @author YHQ 
	 * @since V2.5.6
	 * @return ResValidateCode    返回类型
	 * 
	 */
	@Override
	@Transactional(readOnly = true)
	public ResValidateCode getRecruitUser(String telPhone) {
		
		try {
			return sqlBaseDao.sqlToCustomBeanUnique(ResValidateCode.class, DriverRecruitSQL.GET_DRIVER_RECRUIT_STATUS, telPhone);
		} catch (Exception e) {
			log.error("获取司机招募报名信息时出现异常   类：" + this.getClass() + " getDriverRecruitInfo()", e);
		}
		
		return null;
	}
	
}
